<!DOCTYPE html>
<html>

	<head>

		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>H+ 后台主题UI框架 - 空白页</title>
		<meta name="keywords" content="">
		<meta name="description" content="">

		<link rel="shortcut icon" href="favicon.ico">
		<link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
		<link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
		<link href="__STATIC__/layout/css/font-awesome.css?v=4.4.0" rel="stylesheet">
		<!-- jqgrid-->
		<link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
		<link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
		<link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
		<link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
		<link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
		<script src="__STATIC__/layout/js/jquery.min.js?v=2.1.4"></script>
		<script src="__STATIC__/sc/js/page.js"></script>
	</head>

	<body style="color:#333;padding:3px;" class="x_sorll">
		<!-- 标题 -->
		<div class="page-heade">
			<h2 class="title_color text-center">物料价格管理</h2>
		</div>
		<!-- 标题 -->
		<div class="row-margin-top">
			<form action="#" method="post" class="form-inline formpage" id="form_check">
				<input type="hidden" value='{$page}' name="page" id="page-go" />
				<input type="hidden" value='{$list}' name="list" id="list-go" />
				<table class="row-margin-top tab-content table-bordered  table" border="1">
					<tr>
						<td colspan="6">
							<button class="btn btn-info newgys" type="button">新增价格分组</button>
							<button class="btn btn-info daochufenzu" type="button">导出分组Excel</button>
							<button class="btn btn-info daorugroup" type="button">导入分组</button>
							<button class="btn btn-info daochujxs" type="button">导出经销商Excel</button>
							<button class="btn btn-info daorujxs" type="button">导入经销商</button>
							<button class="btn btn-info daochupro" type="button">导出价格Excel</button>
							<button class="btn btn-info daoruprice" type="button">导入价格</button>
						</td>
					</tr>
					<tr>
						<td style="min-width: 140px" class="text-right"><label for="" class="form-label">分组编号：</label></td>
						<td><input type="text" class="form-control" name="group_no" value="{$data.group_no}"></td>
						<td style="min-width: 140px" class="text-right"><label for="" class="form-label">分组名称：</label></td>
						<td><input type="text" class="form-control" name="group_name" value="{$data.group_name}"></td>
						<td style="min-width: 140px" class="text-right"><label for="" class="form-label">经销商名称：</label></td>
						<td><input type="text" class="form-control" name="jxs_name" value="{$data.jxs_name}"></td>
					</tr>
					<tr>
						<td style="min-width: 140px" class="text-right"><label for="" class="form-label">经销商代码：</label></td>
						<td colspan="5"><input type="text" class="form-control" name="jxs_no" value="{$data.jxs_no}"></td>

					</tr>
					<tr>
						<td colspan="6" class="text-center">
							<button class="btn btn-info query" type="button" id="check">查询</button>
							<button class="btn btn-info emptyIf" type="button" id="clear_check">清空查询条件</button>

						</td>
					</tr>
				</table>
				<table class="table table-bordered table-hover text-center" id="verifytable">
					<tr>
						<th colspan="17">
							<button class="btn btn-info pishanchu" type="button">批量删除</button></th>
					</tr>
					<tr class="info text-center">
						<th style="vertical-align: middle !important;text-align: center;"><input type="checkbox" id="qx"></th>
						<th class="text-center">No.</th>
						<th class="text-center">分组编号</th>
						<th class="text-center">分组名</th>
						<th class="text-center">包含经销商数</th>
						<th class="text-center">包含产品数</th>
						<th class="text-center">创建人</th>
						<th class="text-center">创建时间</th>
						<th class="text-center">修改人</th>
						<th class="text-center">修改时间</th>
						<th class="text-center">操作</th>
					</tr>
					<tbody>
						{volist name="applys" id="vo"}
						<tr class="text-center">
							<td><input type="checkbox" class="dx" value="{$vo.id}" /></td>
							<td>{$i}</td>
							<td>
								<a onclick="details({$vo.id})">{$vo.group_no}</a>
							</td>
							<td>
								<a onclick="details({$vo.id})">{$vo.group_name}</a>
							</td>
							<td>{$vo.gysnum}</td>
							<td>{$vo.pronum}</td>
							<td>{$vo.cname}</td>
							<td>{$vo.created_on}</td>
							<td>{$vo.mname}</td>
							<td>{$vo.modifiled_on}</td>
							<td>
								<a onclick="xiugai({$vo.id})">修改</a>
								<a href="{:url('jxslist')}?gid={$vo.id}">维护供应商</a>
								<a href="{:url('matlist')}?gid={$vo.id}">维护产品和价格</a>
								<a onclick="shanchu({$vo.id})">删除</a>
							</td>
						</tr>
						{/volist}
				</table>
				<h5 class="text-center" id="pagesc" style="font-size: 16px;font-weight: 500">
            			<script>
                            $(function(){
                                pageSC("pagesc",{$sum},{$page},{$maxpage})
                            })
                        </script>
                        	每页显示
           			<select id="pagesize">
                        <option value='10' {if condition="$list eq 10"}selected{/if}>10条</option>
                        <option value='15'{if condition="$list eq 15"}selected{/if}>15条</option>
                        <option value='20'{if condition="$list eq 20"}selected{/if}>20条</option>

            		</select>
        		</h5>
			</form>
		</div>
		<!-- 全局js -->
		<script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
		<!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
		<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
		<script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
		<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
		<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
		<script src="__STATIC__/layout/js/common.js"></script>
		<script>
			function details(gid) {

				var index = layer.open({
					type: 2,
					title: '分组详情',
					area: ['100%', '100%'],
					maxmin: true,
					content: "{:url('price_fz_detail')}?gid=" + gid
				})
			}
			$(".daochupro").click(function() {
				location.href = "{:url('prodaochu')}";
			})
			$(".daoruprice").click(function() {
				location.href = "{:url('daoruprice')}";
			})
			$(".daorujxs").click(function() {
				location.href = "{:url('daorujxs')}";
			})
			$(".daochujxs").click(function() {
				location.href = "{:url('daochujxs')}";
			})
			$(".daochufenzu").click(function() {
				location.href = "{:url('fenzuout')}";
			})
			$(".daorugroup").click(function() {
				location.href = "{:url('daorugroup')}";
			})
			//编号正则
			var reg_no = /^\d{1,4}$/;

			//全选
			$("#qx").change(function() {
				if($(this).prop("checked"))
					$(".dx").prop("checked", true);
				else
					$(".dx").prop("checked", false);
			})
			//单选
			$(".dx").change(function() {
				var flag = 1;
				$(".dx").each(function() {
					if($(this).prop("checked") == false) {
						flag = 0;
					}
				})
				if(flag == 1) {
					$("#qx").prop("checked", true);
				} else {
					$("#qx").prop("checked", false);
				}
			})
			//批量删除
			$(".pishanchu").click(function() {
				var gids = [];
				var i = 0;
				$(".dx").each(function() {
					if($(this).prop("checked")) {
						gids[i] = $(this).val();
						i++;
					}
				})
				if(i == 0) {
					swal({
						title: "完成",
						text: "至少选中一条要删除的数据",
						type: "warning"
					})
				} else {
					var str = gids.join(',');
					swal({
							title: "提示",
							text: "一旦删除则本分组关联的经销商与价格数据都将清空，且不能恢复，确定删除吗？",
							type: "warning",
							showCancelButton: true,
							confirmButtonColor: "#FF3333",
							confirmButtonText: "确定",
							cancelButtonText: "取消",
							closeOnConfirm: true
						}, function(isConfirm) {
							if(isConfirm) {
								//删除操作
								$.post("{:url('shanchu')}", {
									gid: str
								}, function(re) {
									var data = JSON.parse(re);
									if(data["state"] == 1) {
										layer.closeAll();
										swal({
											title: "完成",
											text: "操作已成功",
											type: "success"
										}, function() {

											location.href = "{:url('manage')}";
										});
									} else {
										swal({
											title: "错误",
											text: data["msg"],
											type: "warning"
										})
									}

								})
							}
						}

					)
				}
			})
			//删除
			function shanchu(gid) {
				swal({
						title: "提示",
						text: "一旦删除则本分组关联的经销商与价格数据都将清空，且不能恢复，确定删除吗？",
						type: "warning",
						showCancelButton: true,
						confirmButtonColor: "#FF3333",
						confirmButtonText: "确定",
						cancelButtonText: "取消",
						closeOnConfirm: true
					}, function(isConfirm) {
						if(isConfirm) {
							//删除操作
							$.post("{:url('shanchu')}", {
								gid: gid
							}, function(re) {
								var data = JSON.parse(re);
								if(data["state"] == 1) {
									layer.closeAll();
									swal({
										title: "完成",
										text: "操作已成功",
										type: "success"
									}, function() {

										location.href = "{:url('manage')}";
									});
								} else {
									swal({
										title: "完成",
										text: data["msg"],
										type: "warning"
									})
								}

							})
						}
					}

				)
			}
			//修改
			function xiugai(gid) {
				$.post("{:url('get_group')}", {
					gid: gid
				}, function(re) {
					var data = JSON.parse(re);
					var str = '<form  class="form-inline" style="margin:10px"><table class="table-bordered table"><tr><th class="info" colspan="2">新增价格分组</th></tr><tr><td style="min-width:120px;width:120px;" class="text-center">分组编号<span class="colorRed">*</span></td><td><input type="text" id="group_no" value="' + data["group_no"] + '" class="form-control"/>(最多4位数字，不允许重复)</td></tr><tr><td style="min-width:120px;width:120px;" class="text-center">分组名称<span class="colorRed">*</span></td><td><input type="text" id="group_name" value="' + data["group_name"] + '" class="form-control"/>(不允许重复)</td></tr><tr><td style="min-width:120px;width:120px;" class="text-center">备注</td><td><textarea style="width:400px;height:80px;resize:none;" class="form-control" id="remark">' + data["remark"] + '</textarea></td></tr></table><div class="row" style="width:100%;height:20px;text-align:center;color:red;" id="ts"></div> <div class="row sub_btn" style="width:100%;text-align:center;"><input type="button" id="queding" class="btn btn-success" value="确定"><input type="button" class="btn btn-warning" value="返回" id="cancelBack" style="margin-left:20px"></div></form>'

					layer.open({
						type: 1,
						title: "",
						skin: 'layui-layer-rim', //加上边框
						area: ['600px', '400px'], //宽高
						content: str
					});
					var cancelBack = document.getElementById('cancelBack')
					cancelBack.onclick = function() {
						layer.closeAll();
					}
					var queding = document.getElementById('queding')
					queding.onclick = function() {
						msg = "";

						if($("#group_no").val() == "") {
							msg = "编号不能为空";
						} else if(!reg_no.test($("#group_no").val())) {
							msg = "编号为数字组成且最多4位";
						} else if($("#group_name").val() == "") {
							msg = "分组名不能为空";
						}
						$("#ts").html(msg);
						if(msg == "") {
							queding.disabled = true;
							$.post("{:url('updategroup')}", {
								group_no: $("#group_no").val(),
								group_name: $("#group_name").val(),
								remark: $("#remark").val(),
								gid: gid
							}, function(re) {
								queding.disabled = false;
								var data = JSON.parse(re);
								if(data["state"] == 1) {
									layer.closeAll();
									swal({
										title: "完成",
										text: "操作已成功",
										type: "success"
									}, function() {

										location.href = "{:url('manage')}";
									});
								} else {
									$("#ts").html(data["msg"]);
								}
							})
						}

						//layer.closeAll(); 
					}
				})
			}

			/*添加*/
			$(".newgys").click(function() {
				var str = '<form  class="form-inline" style="margin:10px"><table class="table-bordered table"><tr><th class="info" colspan="2">新增价格分组</th></tr><tr><td style="min-width:120px;width:120px;" class="text-center">分组编号<span class="colorRed">*</span></td><td><input type="text" id="group_no" class="form-control"/>(最多4位数字，不允许重复)</td></tr><tr><td style="min-width:120px;width:120px;" class="text-center">分组名称<span class="colorRed">*</span></td><td><input type="text" id="group_name" class="form-control"/>(不允许重复)</td></tr><tr><td style="min-width:120px;width:120px;" class="text-center">备注</td><td><textarea style="width:400px;height:80px;resize:none;" class="form-control" id="remark"></textarea></td></tr></table><div class="row" style="width:100%;height:20px;text-align:center;color:red;" id="ts"></div> <div class="row sub_btn" style="width:100%;text-align:center;"><input type="button" id="queding" class="btn btn-success" value="确定"><input type="button" class="btn btn-warning" value="返回" id="cancelBack" style="margin-left:20px"></div></form>'
				layer.open({
					type: 1,
					title: "",
					skin: 'layui-layer-rim', //加上边框
					area: ['600px', '400px'], //宽高
					content: str
				});
				var cancelBack = document.getElementById('cancelBack')
				cancelBack.onclick = function() {
					layer.closeAll();
				}
				var queding = document.getElementById('queding')
				queding.onclick = function() {
					// alert($("#remark").val());
					msg = "";

					if($("#group_no").val() == "") {
						msg = "编号不能为空";
					} else if(!reg_no.test($("#group_no").val())) {
						msg = "编号为数字组成且最多4位";
					} else if($("#group_name").val() == "") {
						msg = "分组名不能为空";
					}
					$("#ts").html(msg);
					if(msg == "") {
						queding.disabled = true;
						$.post("{:url('addgroup')}", {
							group_no: $("#group_no").val(),
							group_name: $("#group_name").val(),
							remark: $("#remark").val()
						}, function(re) {
							queding.disabled = false;
							var data = JSON.parse(re);
							if(data["state"] == 1) {
								layer.closeAll();
								swal({
									title: "完成",
									text: "操作已成功",
									type: "success"
								}, function() {

									location.href = "{:url('manage')}";
								});
							} else {
								$("#ts").html(data["msg"]);
							}
						})
					}

					//layer.closeAll(); 
				}
			})
			//翻页
			
			$("#check").click(function() {
				$("#page-go").val(1);
				$(".formpage").submit();
			})
			$("#clear_check").click(function() {
				$("input[type='text']").val("");

				$("#page-go").val(1);
				$(".formpage").submit();
			})
		</script>
	</body>

</html>